/*
 * Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com>
 *
 * The software is licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package com.lv.service.weidget.picker;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.CollectionUtils;
import com.github.gzuliyujiang.wheelpicker.contract.LinkageProvider;
import com.lv.service.bean.TelSecondCategory;
import com.lv.service.bean.TelThirdCategory;
import com.lv.service.room.category.CategoryBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者： ygx
 * 创建日期：2023/4/11 9:48 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：二级联动数据
 */
public class ThirdLikeProvider implements LinkageProvider {
    private List<CategoryBean> mCategoryBeans;

    public ThirdLikeProvider(List<CategoryBean> categoryBeans) {
        mCategoryBeans = categoryBeans;
    }

    @Override
    public boolean firstLevelVisible() {
        return true;
    }

    @Override
    public boolean thirdLevelVisible() {
        return true;
    }

    @NonNull
    @Override
    public List<CategoryBean> provideFirstData() {
        return mCategoryBeans;
    }

    @NonNull
    @Override
    public List<TelSecondCategory> linkageSecondData(int firstIndex) {
        List<TelSecondCategory> telSecondCategories = mCategoryBeans.get(firstIndex).getTelSecondCategories();
        if (CollectionUtils.isEmpty(telSecondCategories)) {
            return new ArrayList<>();
        } else {
            return telSecondCategories;
        }
    }

    @NonNull
    @Override
    public List<TelThirdCategory> linkageThirdData(int firstIndex, int secondIndex) {
        List<TelSecondCategory> telSecondCategories = mCategoryBeans.get(firstIndex).getTelSecondCategories();
        if (CollectionUtils.isEmpty(telSecondCategories)) {
            return new ArrayList<>();
        } else {
            List<TelThirdCategory> telThirdCategories = telSecondCategories.get(secondIndex).getTelThirdCategories();
            if (CollectionUtils.isEmpty(telThirdCategories)) {
                return new ArrayList<>();
            } else {
                return telThirdCategories;
            }
        }
    }

    @Override
    public int findFirstIndex(Object firstValue) {
        return (int) firstValue;
    }

    @Override
    public int findSecondIndex(int firstIndex, Object secondValue) {
        return (int) secondValue;
    }

    @Override
    public int findThirdIndex(int firstIndex, int secondIndex, Object thirdValue) {
        return (int) thirdValue;
    }

}
